# plugs/running.py
#
#

from ommbot.world import add_cmnd, add_example
from ommbot.statdict import Statdict
import threading

def handle_running(bot, ievent):
    """ running .. show running threads """
    stats = Statdict()
    threadlist = threading.enumerate()
    for thread in threadlist:
        stats.upitem(thread.getName())
    txt = ""
    for item in stats.top():
        txt += "%s = %s " % (item[0], item[1])
    ievent.reply(txt)

add_cmnd('running', handle_running, ['USER', 'WEB'])
add_example('running', 'show from which files threads are running', 'running')
